package com.ie.sevice.admin;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ie.common.http.ResponseResult;
import com.ie.entity.OrdersEntity;
import com.ie.mapper.admin.OrdersMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service

public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, OrdersEntity> implements OrdersService{

    @Override
    public ResponseResult<Map<String, Object>> getAllOrders(OrdersEntity ordersEntity) {
        IPage<OrdersEntity> iPage = new Page<>(ordersEntity.getCurrentPage(), 5);
        //构造条件
        QueryWrapper<OrdersEntity> queryWrapper = new QueryWrapper<>();
        if (ordersEntity.getId() != null && ordersEntity.getId() > 0)
            queryWrapper.eq("id", ordersEntity.getId());

        //分页查询
        IPage<OrdersEntity> page = page(iPage, queryWrapper);
        Map<String, Object> myres = new HashMap<>();
        myres.put("allOrders", page.getRecords());
        myres.put("AllOrders", page.getPages());
        return ResponseResult.getSuccessResult(myres);
    }
}
